package com.video_study.controller;

import com.video_study.pojo.LookRecord;
import com.video_study.pojo.Users;
import com.video_study.result.ResponseData;
import com.video_study.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.File;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    UserService userService;


    @GetMapping("/userlogin")
    public ResponseData login(String username,String password){
        return  userService.login(username,password);
    }

    @RequestMapping(value = "/getUserById",method = RequestMethod.GET)
    public ResponseData getUserById(String id){
        return userService.getUserById(id);
    }
    @PostMapping("/userregister")
    @ResponseBody

    public ResponseData register(@RequestBody Users users,HttpServletRequest request){
        return userService.addUser(users,request);

    }


    @RequestMapping(value = "/users",method = RequestMethod.GET)
    public ResponseData getUsers(Integer page ,Integer limit,String id,String username,String phone){
            System.out.println(id+username+phone+"????????????????????????????");
        return userService.getUsers(page,limit,id,username,phone);
    }

    @RequestMapping(value = "/up",method = RequestMethod.POST)
    public ResponseData upImg(MultipartFile file, HttpServletRequest httpRequest){
        return userService.upImg(file,httpRequest);
    }

    @RequestMapping(value = "/adduser",method = RequestMethod.POST,consumes = "application/json")
    public ResponseData up(@RequestBody Users users,HttpServletRequest request){
        return userService.addUser(users,request);
    }

    @RequestMapping(value = "/update",method = RequestMethod.POST,consumes = "application/json")
    public ResponseData edit(@RequestBody Users users){
        return userService.editUser(users);
    }

    @RequestMapping(value = "/findpwd",method = RequestMethod.POST,consumes = "application/json")
    public ResponseData findpwd(@RequestBody Users users){
        return userService.findpwd(users);
    }

    @RequestMapping(value = "/",method = RequestMethod.DELETE)
    public ResponseData delete(@RequestBody String[] ids){
        return userService.deleteById(ids);
    }

    @RequestMapping(value = "/getReserves",method = RequestMethod.GET)
    public ResponseData getReserves(String id){
        return userService.getReserves(id);
    }

    @RequestMapping(value = "/insertRecords",method = RequestMethod.GET)
    public ResponseData insertRecords(LookRecord lookRecord){
        return userService.insertRecords(lookRecord);
    }

    @RequestMapping(value = "/getRecords",method = RequestMethod.GET)
    public ResponseData getRecords(String id){
        return userService.getRecords(id);
    }
}
